<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="multipart/form-data;charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" th:href="@{../bootstrap/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{../css/font-awesome.min.css}">
    <link rel="stylesheet" th:href="@{../css/main.css}">


    <style>
        .tree li {
            list-style-type: none;
            cursor:pointer;
        }
        table tbody tr:nth-child(odd){background:#F4F4F4;}
        table tbody td:nth-child(even){color:#C00;}
        select,option{
            font-size: 20px;
        }
        .myModal-input{
            width: 200px;
            line-height: 30px;
            display: inline;
        }
        .modal-header{
            background-color: #6495ED;
        }
        .modal-dialog{
            width:900px;
        }
        .close{
            background-color: red;
        }
        .img{
            width:120px;
            height: 120px;
        }
        .imgDiv{
            position: absolute;
            left: 560px;

        }
        label{
            display: inline-block;
            min-width: 70px;/*或者 width: 100px;*/
        }
    </style>
</head>

<body>

<div th:replace="../templates/nav"></div>
<div class="container-fluid">
    <div class="row">
        <div th:replace="../templates/menu"></div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 用户信息</h3>
                </div>
                <div class="panel-body">
                    <form class="form-inline" role="form" style="float:left;" id="searchForm">
                        <div class="form-group has-feedback">
                            地区：<select id="option" class="form-control" name="area"></select>
                            </select>

                            <div class="input-group">
                                <div class="input-group-addon">姓名</div>
                                <input class="form-control has-success" type="text" placeholder="请输入查询条件" name="uname" id="uname">
                            </div>
                            <div class="input-group">
                                <div class="input-group-addon">账号</div>
                                <input class="form-control has-success" type="text" placeholder="请输入查询条件" name="uaccount" id="uaccount">
                            </div>
                        </div>
                        <button type="button" class="btn btn-warning" id="btnSearch"><i class="glyphicon glyphicon-search"></i> 搜索</button>
                    </form>

                    <button type="button"  style="float:right;height: 33px" onclick="changepermission()"><i class="glyphicon"></i> 更改权限</button>
                    <!--                    <button type="button" class="btn btn-primary" style="float:right;" data-toggle="modal" data-target="#myModal6" onclick="changepermission()"><i class="glyphicon"></i> 更改权限</button>-->
                    <button type="button" class="btn btn-danger" onclick="lockmany()" style="float: right;margin-right: 10px">更改锁值</button>
                    <button type="button" class="btn btn-primary" style="float:right;" data-toggle="modal" data-target="#myModal5" onclick="save()"><i class="glyphicon glyphicon-plus"></i> 新增</button>
                    <br>
                    <hr style="clear:both;">
                    <div class="table-responsive">
                        <form id="lockForm">
                            <table class="table  table-bordered">
                                <thead>
                                <tr >
                                    <th style='text-align: center'>#</th>
                                    <th style='text-align: center'>姓名</th>
                                    <th style='text-align: center'>账号</th>
                                    <th style='text-align: center'>地区</th>
                                    <th style='text-align: center'>电话</th>
                                    <th style='text-align: center'>状态</th>
                                    <th style='text-align: center'>锁值</th>
                                    <th width="50" style='text-align: center'>锁定</th>
                                    <th width="150"  style='text-align: center'>操作</th>
                                </tr>
                                </thead>
                                <tbody id="tbody">

                                </tbody>

                                <tfoot>
                                <tr >
                                    <td colspan="12" align="center">
                                        <ul class="pagination" id="byPage">

                                        </ul>
                                    </td>
                                </tr>
                                </tfoot>
                            </table>
                        </form>
                    </div>
                </div>
            </div>

            <!-- 模态框（Modal）修改老师信息-->
            <form id="updateForm">
                <div class="modal fade myModel" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                <h4 class="modal-title" id="myModalLabel">修改用户信息</h4>
                            </div>
                            <input type="hidden" name="sid" id="sid2">
                            <div class="modal-body">

                                <div class="form-group">
                                    <input th:type="hidden" id="uid3" name="uid" ></input>
                                    <label style="float:left;margin-top: 5px" >地区：</label><select id="area3" name="area" class="form-control" style="width: 200px;height: 30px;float:left;" ></select>
                                    <label style="float:left;margin-top: 5px;margin-left: 3px"  >状态：</label><select id="ustate3" class="form-control" name="ustate" style="width: 200px;height: 30px"></select><br/>
                                </div>
                                <div class="form-group">
                                    <label for="uname3">姓名：</label><input name="uname" id="uname3" class="form-control myModal-input">
                                    <input name="uaccount" id="uaccount3" type="hidden" class="form-control myModal-input">
                                    <input name="area4" id="area4" type="hidden" class="form-control myModal-input">
                                    <input name="ustate4" id="ustate4" type="hidden" class="form-control myModal-input">
                                    <label for="uphone3">电话：</label><input name="uphone" id="uphone3" class="form-control myModal-input">
                                </div>

                            </div>

                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                <button type="button" class="btn btn-primary" id="btnupdate">提交更改</button>
                            </div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal-dialog -->
                </div>
            </form>
            <!-- 模态框（Modal）新增老师信息-->
            <form id="AddForm" enctype="multipart/form-data">
                <div class="modal fade myModel" id="myModal5" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                <h4 class="modal-title" id="myModalLabel5">增加用户</h4>
                            </div>
                            <div class="modal-body">
                                <div class="form-group">
                                    校区：<select id="area2" class="form-control" name="area" style="width: 250px"></select></select>
                                </div>
                                <div class="form-group">
                                    角色：<select id="rid2" class="form-control" name="rid" style="width: 250px"></select></select>
                                </div>



                                <div class="form-group">
                                    <label for="uname2">姓名：</label><input name="uname" id="uname2" class="form-control myModal-input">
                                    <label for="uaccount2">账号：</label><input name="uaccount" id="uaccount2" class="form-control myModal-input">
                                </div>
                                <div class="form-group">
                                    <label for="uphone2">电话：</label><input name="uphone" id="uphone2" class="form-control myModal-input">
                                </div>
                                <!--                                其他默认属性-->
                                <div>
                                    <label for="ustate2"></label><input th:type="hidden" name="ustate" id="ustate2" th:value="正常" class="form-control myModal-input">
<!--                                    <label for="upwd2"></label><input th:type="hidden" name="upwd" id="upwd2" th:value="123456" class="form-control myModal-input">-->
                                    <label for="softdel2"></label><input th:type="hidden" name="softdel" id="softdel2" th:value="1" class="form-control myModal-input">
                                </div>
                            </div>

                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                <button type="button" class="btn btn-primary" id="btnAdd">保存</button>
                            </div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal-dialog -->
                </div>
            </form>
            <!-- 模态框（Modal）修改老师角色-->
            <form id="permissionForm">
                <div class="modal fade myModel" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                <h4 class="modal-title" id="myModalLabel2">修改用户角色</h4>
                            </div>

                            <div class="modal-body">
                                <form role="form" class="form-inline" id="roleForm">
                                    <input type="hidden" name="uid" id="uid4">
                                    <br><br>
                                    <div class="form-group" style="width: 250px;height: 250px;float: left;margin-top: 10px" >
                                        <label for="unassignPermission">未分配角色列表</label><br>
                                        <select class="form-control"  size="10" style="width:100px;overflow-y:auto;height: 160px" id="unassignPermission">
                                        </select>
                                    </div>

                                    <div class="form-group" style="width: 250px;float: left;margin-top: 50px">
                                        <ul>
                                            <li class="btn btn-default glyphicon glyphicon-chevron-right" id="left2Right"></li>
                                            <br>
                                            <li class="btn btn-default glyphicon glyphicon-chevron-left" style="margin-top:20px;" id="right2Left"></li>
                                        </ul>
                                    </div>

                                    <div class="form-group" style="width: 200px;height: 250px;float:left;margin-top: 10px">
                                        <label for="assignPermission">已分配角色列表</label><br>
                                        <select class="form-control"  size="10" style="width:100px;overflow-y:auto;height: 160px" id="assignPermission">
                                        </select>
                                    </div>
                                </form>
                                <br> <br> <br> <br> <br> <br> <br> <br> <br><br> <br>

                            </div>

                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal" id="closebtn">关闭</button>
<!--                                <button type="button" class="btn btn-primary" onclick="closs()">完成修改 </button>-->
                            </div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal-dialog -->
                </div>
            </form>
            <!-- 模态框（Modal）修改权限-->
            <form id="permissionForm2">
                <div class="modal fade myModel" id="myModal6" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                <h4 class="modal-title" id="myModalLabel6">修改用户权限</h4>
                            </div>

                            <div class="modal-body">
                                <form role="form" class="form-inline" id="permisssionForm">
                                    <input type="hidden" name="rid" id="rid6">
                                    角色：<select id="option6" class="form-control" name="rid" style="float:left;"></select>
                                    <button onclick="serch()" style="float:left;">搜索</button>

                                    <div class="form-group" style="width: 250px;height: 250px;float: left;margin-top: 10px" >
                                        <label for="unassignPermission">未分配权限列表</label><br>
                                        <select class="form-control"  size="10" style="width:100px;overflow-y:auto;height: 160px" id="unassignPermission2">
                                        </select>
                                    </div>

                                    <div class="form-group" style="width: 250px;float: left;margin-top: 50px">
                                        <ul>
                                            <li class="btn btn-default glyphicon glyphicon-chevron-right" id="left2Right2"></li>
                                            <br>
                                            <li class="btn btn-default glyphicon glyphicon-chevron-left" style="margin-top:20px;" id="right2Left2"></li>
                                        </ul>
                                    </div>

                                    <div class="form-group" style="width: 200px;height: 250px;float:left;margin-top: 10px">
                                        <label for="assignPermission">已分配权限列表</label><br>
                                        <select class="form-control"  size="10" style="width:100px;overflow-y:auto;height: 160px" id="assignPermission2">
                                        </select>
                                    </div>
                                </form>
                                <br> <br> <br> <br> <br> <br> <br> <br> <br><br> <br>

                            </div>

                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal" >关闭</button>

                                <button type="button" class="btn btn-primary" >完成修改 </button>
                            </div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal-dialog -->
                </div>
            </form>

        </div>
    </div>
</div>
<script th:src="@{../jquery/jquery.min.js}"></script>
<script th:src="@{../jquery/qrcode.min.js}"></script>
<script th:src="@{../jquery/jquery-2.1.1.min.js}"></script>
<script th:src="@{../bootstrap/js/bootstrap.min.js}"></script>
<script th:src="@{../script/docs.min.js}"></script>
<script th:src="@{../layer/layer.js}"></script>

<script type="text/javascript">
    //页面初始函数
    $(function () {
        $(".list-group-item").click(function(){
            if ( $(this).find("ul") ) {
                $(this).toggleClass("tree-closed");
                if ( $(this).hasClass("tree-closed") ) {
                    $("ul", this).hide("fast");
                } else {
                    $("ul", this).show("fast");
                }
            }
        });
        //回填地区
        area();
        //分页展示
        showList(1);
    });
    //按照条件查询
    $("#btnSearch").click(function () {
        showList(1);
    });
    //地区填充
    function area() {
        url1 = "/role/areaDo";
        $.get(url1, "", function (data) {
            if (data.result) {
                var htmldata1 = "<option  value='' >蜗牛校区</option>";
                $.each(data.schoolList, function (index, school) {
                    htmldata1 = htmldata1 + "<option value=" + school.schname + " >" + school.schname + "</option>";
                })
                $("#option").html(htmldata1);
            }
        })
    }
    //分页展示(不展示自己 解锁 、 开锁)
    function showList(currentPage) {
        $.ajax({
            url:"/role/listDo",
            type:"get",
            data:{"currentPage":currentPage,"area":$("#option").val(),"uaccount":$("#uaccount").val(),"uname":$("#uname").val()},
            success:function (data) {
                if (data.result){
                    var uid2 = data.cuurrentuid;
                    var str="";

                    $.each(data.userList, function (index, user){
                        var state = 0;
                        if(user.userroleList.length > 0 ){
                            $.each(user.userroleList, function (index, userrole) {
                                if(userrole.rid == 4){
                                    state = 1;
                                }
                            })
                        }
                        str += "<tr style='text-align: center'>";
                        if(user.uid == uid2 || state == 1){str += "<td><input type='hidden' name='uid' value='"+user.uid+"'></td>";}
                        else{ str += "<td><input type='checkbox' name='uid' value='"+user.uid+"'></td>"};
                        str += "<td>" + user.uname + "</td>";
                        str += "<td>" + user.uaccount + "</td>";
                        str += "<td>" + user.area + "</td>";
                        str += "<td>" + user.uphone + "</td>";
                        str += "<td>" + user.ustate + "</td>";
                        if(user.softdel == 1){str += "<td>已开启</td>";}
                        else {str += "<td>已锁定</td>"; }
                        if(user.uid == uid2 || state == 1) {str += "<td></td>";}
                        else{ str += "<td>" + '<button type="button" class="btn btn-success " onclick="changelock(' + user.uid + ')">锁</button>'; + "</td>";}
                        str += "<td>"
                        if(state == 1){ str += '管理员'}
                        else { str += '<button style="margin-left: 20px" type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModal1" onclick="update(' + user.uid + ')"><i class=" glyphicon glyphicon-pencil"></i></button>';
                            str += '<button style="margin-left: 20px" type="button" class="btn btn-success btn-xs" data-toggle="modal" data-target="#myModal2" onclick="permission(' + user.uid + ')"><i class=" glyphicon glyphicon-check"></i></button>';}
                        str += "</td>";
                        str += "</tr>";
                    });
                    $("#tbody").html(str);
                    var pageStr = "";
                    pageStr += '<li class="' + (data.pageBean.currentPage == 1 ? 'disabled' : '') + '"><a href="#" onclick="showList(' + (data.pageBean.currentPage>=1?data.pageBean.countPage-1:1)+ ')">上一页</a></li>';
                    for (var i = 1; i <= data.pageBean.countPage; i++) {
                        pageStr += '<li class="' + (data.pageBean.currentPage == i ? 'active' : '') + '"><a href="#" onclick="showList(' + i + ')">' + i + '<span class="sr-only">(current)</span></a></li>';
                    }
                    pageStr += '<li class="' + (data.pageBean.currentPage == data.pageBean.countPage ? 'disabled' : '') + '"><a href="#" onclick="showList('+(data.pageBean.currentPage==data.pageBean.countPage?data.pageBean.countPage:data.pageBean.currentPage+1)+')">下一页</a></li>';
                    $("#byPage").html(pageStr);
                } else {
                    layer.msg("数据加载失败", {time: 1000, icon: 5, shift: 6}, function () {
                    });
                }
            }
        });
    }
    //改变用户的锁定状态
    function changelock(uid){
        url="/changesoftdelDo"
        $.get(url,"uid="+uid,function (data){
            if(data.result){
                //分页展示
                showList(1);
                layer.msg("更改成功", {time: 1000, icon: 6, shift: 6}, function () {
                    return
                });
            }
        })
    }
    //批量改变锁定用户
    function lockmany(){
        url="/changesoftdelmanyDo"
        var parm = $("#lockForm").serialize();
        $.get(url,parm,function (data){
            if(data.result){
                //分页展示
                showList(1);
                layer.msg("批量成功", {time: 1000, icon: 6, shift: 6}, function () {
                    return
                });
            }
        })
    }
    //打开新增模态框(数据回填)
    function save(){
        //将地区信息回填
        url1 = "/role/areaDo";
        $.get(url1, "", function (data) {
            if (data.result) {
                var htmldata1 = "<option  value='' >蜗牛校区</option>";
                $.each(data.schoolList, function (index, school) {
                    htmldata1 = htmldata1 + "<option value=" + school.schname + " >" + school.schname + "</option>";
                })
                $("#area2").html(htmldata1);
            }
        })
        //角色信息回填
        url1 = "/role/rolemanyDo";
        $.get(url1, "", function (data) {
            if (data.result) {
                var htmldata2 = "";
                var htmldata3 = "";
                $.each(data.roleList, function (index, role) {
                    if(role.rname == "老师"){htmldata3 = htmldata3 + "<option value=" + role.rid + " >" + role.rname + "</option>";}
                    else{ htmldata2 = htmldata2 + "<option value=" + role.rid + " >" + role.rname + "</option>";}
                })
                htmldata2 = htmldata3+htmldata2;
                $("#rid2").html(htmldata2);
            }
        })

    }
    //新增保存
    $("#btnAdd").click(function () {
        var area = $("#area2").val();
        if(area == null || area == ""){
            layer.msg("校区信息不能为空", {time: 1000, icon: 5, shift: 6}, function () {
            });
            return;
        }

        var uname2 = $("#uname2").val();
        if(uname2 == null || uname2 == ""){
            layer.msg("姓名不能为空", {time: 1000, icon: 5, shift: 6}, function () {
            });
            return
        }

        var uaccount = $("#uaccount2").val();
        if(uaccount == null || uaccount == ""){
            layer.msg("账号不能为空", {time: 1000, icon: 5, shift: 6}, function () {
            });
            return
        }
        var uphone = $("#uphone2").val();
        if(uphone == null || uphone == ""){
            layer.msg("电话号码不能为空", {time: 1000, icon: 5, shift: 6}, function () {
            });
            return
        }else if(!(/^1[3456789]\d{9}$/.test(uphone))){
            layer.msg("电话号码长度或格式不满足要求", {time: 1000, icon: 5, shift: 6}, function () {
            });
            return
        }
        var formdata = $("#AddForm").serialize();
        $.ajax({
            url: "/saveoneDo",
            type: "post",
            dataType:"json",
            // async:false,
            // cache:false,
            // contentType:false,
            // processData:false,
            data: formdata,
            success: function (data) {
                if (data.result) {
                    //模态框数据清除
                    $("#AddForm")[0].reset();
                    //模态框隐藏(点击其他区域)
                    $("#AddForm").modal("hide");
                    showList(1);
                    layer.msg("注册成功", {time: 1000, icon: 6, shift: 6}, function () {
                    });
                }else{
                    layer.msg("注册的账号已存在", {time: 1000, icon: 4, shift: 6}, function () {
                    });
                }
            }
        });
    });
    //打开修改模态框(数据回填)
    function update(uid){
    //将user信息回填
    url1 = "/updateDo";
    $.get(url1, "uid="+uid, function (data) {
        if (data.result) {
            $("#uid3").val(data.user.uid);
            $("#uname3").val(data.user.uname);
            $("#uaccount3").val(data.user.uaccount);
            $("#uphone3").val(data.user.uphone);
            $("#area4").val(data.user.area);
            $("#ustate4").val(data.user.ustate);
        }
        //将地区信息回填
        url1 = "/role/areaDo";
        $.get(url1, "", function (data) {
            if (data.result) {
                //所有区域回填
                var area = $("#area4").val();
                var htmldata1 = "";
                $.each(data.schoolList, function (index, school) {
                    if(school.schname == area){
                        htmldata1 = htmldata1 + "<option value=" + school.schname + " selected >" + school.schname + "</option>";
                    }else {
                        htmldata1 = htmldata1 + "<option value=" + school.schname + " >" + school.schname + "</option>";
                    }
                })
                $("#area3").html(htmldata1);
            }
        })

        //所有用户的状态值回填
        url1 = "/ustateDo";
        $.get(url1,"", function (data) {
            if (data.result) {
                //所有状态 及用户信息 回填
                var ustate = $("#ustate4").val()
                var htmldata2 = "";
                $.each(data.stateList, function (index, state) {
                    if(state == ustate){   //此处state后续改为session取值
                        htmldata2 = htmldata2 + "<option value=" + state + " selected >" + state + "</option>";
                    }else {
                        htmldata2 = htmldata2 + "<option value=" + state + " >" + state + "</option>";
                    }
                })
                $("#ustate3").html(htmldata2);
            }
        })
    })
    }
    //修改提交
    $("#btnupdate").click(function () {

        var uname3 = $("#uname3").val()
        if(uname3 == null || uname3 == ""){
            layer.msg("姓名不能为空", {time: 1000, icon: 4, shift: 6}, function () {
            });
            return;
        }

        var uphone3 = $("#uphone3").val();
        if(uphone3 == null || uphone3 == ""){
            layer.msg("电话号码不能为空", {time: 1000, icon: 4, shift: 6}, function () {
            });
            return
        }else if(!(/^1[3456789]\d{9}$/.test(uphone3))){
            layer.msg("电话号码长度或格式不满足要求", {time: 1000, icon: 4, shift: 6}, function () {
            });
            return
        }
        var formdata = $("#updateForm").serialize();
        $.ajax({
            url: "/updateoneDo",
            type: "post",
            dataType:"json",
            data: formdata,
            success: function (data) {
                if (data.result) {
                    layer.msg("修改成功", {time: 1000, icon: 6, shift: 6}, function () {
                    });
                    //模态框数据清除
                    // $("#updateForm")[0].reset();
                    //模态框隐藏(点击其他区域)
                    // $("#updateForm").modal("hide");
                    showList(1)
                    $("#area3").val(data.user.area);
                    $("#ustate3").val(data.user.ustate);
                    $("#uname3").val(data.user.uname);
                    $("#uphone3").val(data.user.uphone);


                }else{
                    layer.msg("账号已存在", {time: 1000, icon: 4, shift: 6}, function () {
                    });
                }
            }
        });
    });
    //角色模态框展示
    function permission(uid){
        url="/roleshowDo"
        $.get(url,"uid="+uid,function (data) {
            if(data.result) {
                $("#uid4").val(data.uid);
                //给未分配的填值
                // $.each(data.unassignperissionList,function (index,permission) {
                //     var unassign = $("<option></option>")
                //     unassign.val(permission.pid);
                //     unassign.text(permission.pname)
                //     $("#unassignPermission").append(unassign);
                // })
                if (data.unassignperissionList != null) {
                    var htmldata1 = "";
                    $.each(data.unassignperissionList, function (index, role) {
                        htmldata1 = htmldata1 + "<option value=" + role.rid + " >" + role.rname + "</option>";
                    });
                    $("#unassignPermission").html(htmldata1);
                }
                // if (data.assignpermissionList != null) {
                //     //给已经分配的填值
                //     $.each(data.assignpermissionList, function (index, permission) {
                //         var assign = $("<option></option>")
                //         assign.val(permission.pid);
                //         assign.text(permission.pname)
                //         $("#assignPermission").append(assign);
                //     })
                // }
                if (data.assignpermissionList != null) {
                    var htmldata2 = "";
                    $.each(data.assignpermissionList, function (index, role) {
                        htmldata2 = htmldata2 + "<option value=" + role.rid + " >" + role.rname + "</option>";
                    });
                    $("#assignPermission").html(htmldata2);
                }
            }
        },"json")
    }
    //增加角色
    $("#left2Right").click(function (){
        var uid = $("#uid4").val();
        var rid = $("#unassignPermission").val()
        url = "/saveroleDo"
        $.get(url,"rid="+rid+"&uid="+uid,function (data){
            if(data.result){
                layer.msg("修改成功", {time: 1000, icon: 6, shift: 6}, function () {
                });
                // $("#unassignPermission")[0].reset();
                // $("#assignPermission")[0].reset();
                permission(data.uid);
                showList(1)
            }
        })
    });
    //收回角色
    $("#right2Left").click(function (){
        var uid = $("#uid4").val();
        var rid = $("#assignPermission").val()
        url = "/deleteroleDo"
        $.get(url,"rid="+rid+"&uid="+uid,function (data){
            if(data.result){
                layer.msg("修改成功", {time: 1000, icon: 6, shift: 6}, function () {
                });
                permission(data.uid);
            }else {
                layer.msg("最后一个角色不能删除", {time: 1000, icon: 4, shift: 6}, function () {
                });
            }
        })
    });
    //关闭模态框
    function closs(){
        $("#unassignPermission")[0].reset();
        $("#assignPermission")[0].reset();
        $("#unassignPermission").modal("hide");
        $("#assignPermission").modal("hide");
        $("#closebtn").click()
    }
    //打开权限模态框
    function changepermission() {
        window.location.href = "/permission/enterpermission";
    }

</script>
</body>
</html>







